package com.itheima.nio.buffer.demo09;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class NioClientDemo09 {

    public static void main(String[] args) throws IOException {

        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.connect(new InetSocketAddress("127.0.0.1", 7373));
        ByteBuffer byteBuffer = ByteBuffer.wrap("hello".getBytes("UTF-8"));
        socketChannel.write(byteBuffer);

        ByteBuffer byteBuffer1 = ByteBuffer.allocate(1024);
        System.out.println("准备读取服务器端所返回的数据..............");
        int read = socketChannel.read(byteBuffer);
        System.out.println("读取到了服务器端所返回的数据..............");
        System.out.println(new String(byteBuffer1.array(), 0, read, "UTF-8"));
        System.out.println("读取到了服务器端所返回的数据..........2....");
        socketChannel.close();
    }
}
